package com.seek.util;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

@Component("push2SingleUtil")
public class Push2SingleUtil {

	public static final int TYPE_OF_CERTIFY_SUC=2; // 实名认证审核通过
	public static final int TYPE_OF_CERTIFY_FAIL=3; // 实名认证审核不通过
	public static final int TYPE_OF_CARDBIND_SUC=4; // 银行卡绑定成功
	public static final int TYPE_OF_CARDBIND_FAIL=5; // 银行卡绑定不通过
	public static final int TYPE_OF_MOBILE_SUC=6; // 运营商审核通过
	public static final int TYPE_OF_MOBILE_FAIL=7; // 运营商审核不通过
	public static final int TYPE_OF_ZFB_SUC=8; // 支付宝审核通过
	public static final int TYPE_OF_ZFB_FAIL=9; // 支付宝审核不通过
	public static final int TYPE_OF_ZFB_FAIL_END=10; // 支付宝审核不通过且不允许再提交
	public static final int TYPE_OF_LOANAUDIT_SUC=11; // 货款审核通过
	public static final int TYPE_OF_LOANAUDIT_FAIL=12; // 货款审核不通过
	public static final int TYPE_OF_REPAY_WARNING=13; // 还款提醒
	
	@Resource
	private TheadHelper theadHelper;

	
	public void push2Single(String content, String clientid, String payload) throws Exception {
		if (CommonUtil.isEmpty(clientid) || CommonUtil.isEmpty(content)){
			return;
		}
		theadHelper.getTaskExecutor().execute(new Push2SingleThread(content, clientid, payload));
	}
	
	public void push2Single(int type,String clientid) throws Exception {
		String[] ret = this.getContent(type);
		push2Single(ret[0], clientid, ret[1]);
	}
	
	// 根据类别生成推送内容和payload
	private String[] getContent(int type){
		String[] ret = new String[2];
		if (TYPE_OF_CERTIFY_SUC == type){
			ret[0] = "恭喜您，您的实名认证已通过，请继续完成其他认证吧～";
			ret[1] = "{'appUrl':'huajinbao://auth.list','mTitle':'实名认证成功','logo':'http://huajinbao.b0.upaiyun.com/logo/m_id.png','bText':'继续认证','content':'"+ret[0]+"','type':'"+type+"','createTime':'"+DateUtil.dateFormat(new Date(), DateUtil.DATE_FORMAT_YMDHMS)+"'}";
		}
		if (TYPE_OF_CERTIFY_FAIL == type){
			ret[0] = "抱歉，您的实名认证未通过。请您上传照片进行人工审核";
			ret[1] = "{'appUrl':'huajinbao://auth.list','mTitle':'实名认证失败','logo':'http://huajinbao.b0.upaiyun.com/logo/m_id.png','bText':'继续认证','content':'"+ret[0]+"','type':'"+type+"','createTime':'"+DateUtil.dateFormat(new Date(), DateUtil.DATE_FORMAT_YMDHMS)+"'}";
		}
		if (TYPE_OF_CARDBIND_SUC == type){
			ret[0] = "恭喜您，您的银行卡绑定成功，请继续完成其他认证吧";
			ret[1] = "{'appUrl':'huajinbao://auth.list','mTitle':'银行卡绑定成功','logo':'http://huajinbao.b0.upaiyun.com/logo/m_bank.png','bText':'继续认证','content':'"+ret[0]+"','type':'"+type+"','createTime':'"+DateUtil.dateFormat(new Date(), DateUtil.DATE_FORMAT_YMDHMS)+"'}";
		}
		if (TYPE_OF_CARDBIND_FAIL == type){
			ret[0] = "抱歉，您的银行卡绑定未成功，请您重新申请认证";
			ret[1] = "{'appUrl':'huajinbao://auth.list','mTitle':'银行卡绑定失败','logo':'http://huajinbao.b0.upaiyun.com/logo/m_bank.png','bText':'继续认证','content':'"+ret[0]+"','type':'"+type+"','createTime':'"+DateUtil.dateFormat(new Date(), DateUtil.DATE_FORMAT_YMDHMS)+"'}";
		}
		if (TYPE_OF_MOBILE_SUC == type){
			ret[0] = "恭喜您，运营商认证已通过，请继续完成其他认证吧";
			ret[1] = "{'appUrl':'huajinbao://auth.list','mTitle':'运营商认证成功','logo':'http://huajinbao.b0.upaiyun.com/logo/m_operator.png','bText':'继续认证','content':'"+ret[0]+"','type':'"+type+"','createTime':'"+DateUtil.dateFormat(new Date(), DateUtil.DATE_FORMAT_YMDHMS)+"'}";
		}
		if (TYPE_OF_MOBILE_FAIL == type){
			ret[0] = "抱歉，您的运营商认证未通过，请您重新申请认证";
			ret[1] = "{'appUrl':'huajinbao://auth.list','mTitle':'运营商认证失败','logo':'http://huajinbao.b0.upaiyun.com/logo/m_operator.png','bText':'继续认证','content':'"+ret[0]+"','type':'"+type+"','createTime':'"+DateUtil.dateFormat(new Date(), DateUtil.DATE_FORMAT_YMDHMS)+"'}";
		}
		if (TYPE_OF_ZFB_SUC == type){
			ret[0] = "恭喜您，您的支付宝认证已通过。您可以申请借款啦～";
			ret[1] = "{'appUrl':'huajinbao://go.index','mTitle':'支付宝认证成功','logo':'http://huajinbao.b0.upaiyun.com/logo/m_alipay.png','bText':'去借款','content':'"+ret[0]+"','type':'"+type+"','createTime':'"+DateUtil.dateFormat(new Date(), DateUtil.DATE_FORMAT_YMDHMS)+"'}";
		}
		if (TYPE_OF_ZFB_FAIL == type){
			ret[0] = "抱歉，您的支付宝认证未通过，请您重新申请认证";
			ret[1] = "{'appUrl':'huajinbao://auth.list','mTitle':'支付宝认证失败','logo':'http://huajinbao.b0.upaiyun.com/logo/m_alipay.png','bText':'继续认证','content':'"+ret[0]+"','type':'"+type+"','createTime':'"+DateUtil.dateFormat(new Date(), DateUtil.DATE_FORMAT_YMDHMS)+"'}";
		}
		if (TYPE_OF_ZFB_FAIL_END == type){
			ret[0] = "抱歉，您不符合我们的贷款条件。如有疑问，请联系客服";
			ret[1] = "{'appUrl':'','mTitle':'支付宝认证失败','logo':'http://huajinbao.b0.upaiyun.com/logo/m_alipay.png','bText':'','content':'"+ret[0]+"','type':'"+type+"','createTime':'"+DateUtil.dateFormat(new Date(), DateUtil.DATE_FORMAT_YMDHMS)+"'}";
		}
		if (TYPE_OF_LOANAUDIT_SUC == type){
			ret[0] = "恭喜您，您的贷款申请已审核通过。系统将在1-2个工作日内完成放款～";
			ret[1] = "{'appUrl':'','mTitle':'贷款申请审核通过','logo':'http://huajinbao.b0.upaiyun.com/logo/m_id.png','bText':'','content':'"+ret[0]+"','type':'"+type+"','createTime':'"+DateUtil.dateFormat(new Date(), DateUtil.DATE_FORMAT_YMDHMS)+"'}";
		}
		if (TYPE_OF_LOANAUDIT_FAIL == type){
			ret[0] = "抱歉，您的贷款申请审核未通过";
			ret[1] = "{'appUrl':'','mTitle':'贷款申请审核失败','logo':'http://huajinbao.b0.upaiyun.com/logo/m_loan_no.png','bText':'','content':'"+ret[0]+"','type':'"+type+"','createTime':'"+DateUtil.dateFormat(new Date(), DateUtil.DATE_FORMAT_YMDHMS)+"'}";
		}
		if (TYPE_OF_REPAY_WARNING == type){
			ret[0] = "亲，您有贷款已到期，请及时还款！";
			ret[1] = "{'appUrl':'huajinbao://repay.list','mTitle':'还款提醒','logo':'http://huajinbao.b0.upaiyun.com/logo/m_repay.png','bText':'去还款','content':'"+ret[0]+"','type':'"+type+"','createTime':'"+DateUtil.dateFormat(new Date(), DateUtil.DATE_FORMAT_YMDHMS)+"'}";
		}
		
		return ret;
	}
}
